package com.surveillance.util;


import java.awt.Color;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import com.surveillance.entities.AffectedSurveillants;

public class AffectationSurveillantsPDFBuilder extends AbstractITextPdfView {

	@Override
	protected void buildPdfDocument(Map<String, Object> model, Document doc,
			PdfWriter writer, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// get data model which is passed by the Spring container
		 List<AffectedSurveillants> listAffSurv = (List<AffectedSurveillants>) model.get("affetcedSurvDetail");
		BaseFont fonte = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1250,
				BaseFont.NOT_EMBEDDED);
		Font maFonte = new Font(fonte);
		maFonte.setColor(Color.BLUE);
		maFonte.setStyle(Font.BOLD);
		maFonte.setSize(25.0f);
		doc.add(new Paragraph("Recommended books for Spring framework"));

		PdfPTable table = new PdfPTable(5);
		table.setWidthPercentage(100.0f);
		table.setWidths(new float[] { 3.0f, 2.0f, 2.0f, 2.0f, 1.0f });
		table.setSpacingBefore(10);

		// define font for table header row
		// Font font = FontFactory.getFont(FontFactory.HELVETICA);
		// font.setColor(BaseColor.WHITE);

		// define table header cell
		// PdfPCell cell = new PdfPCell();
		// // cell.setBackgroundColor(BaseColor.BLUE);
		// cell.setPadding(5);
		//
		// // write table header
		// cell.setPhrase(new Phrase("Book Title", font));
		// table.addCell(cell);
		//
		// cell.setPhrase(new Phrase("Author", font));
		// table.addCell(cell);
		//
		// cell.setPhrase(new Phrase("ISBN", font));
		// table.addCell(cell);
		//
		// cell.setPhrase(new Phrase("Published Date", font));
		// table.addCell(cell);
		//
		// cell.setPhrase(new Phrase("Price", font));
		// table.addCell(cell);

		doc.add(new Paragraph(""));
		Paragraph paragraph = new Paragraph("gestion des surveillances",
				maFonte);
		paragraph.setAlignment(Element.ALIGN_CENTER);
		doc.add(paragraph);
		Table table1 = Utilz.createTableSurv(listAffSurv);
		doc.add(table1);

		// write table row data
		// for (Book aBook : listBooks) {
		// table.addCell(aBook.getTitle());
		// table.addCell(aBook.getAuthor());
		// table.addCell(aBook.getIsbn());
		// table.addCell(aBook.getPublishedDate());
		// table.addCell(String.valueOf(aBook.getPrice()));
		// }

		doc.add(table);

	}

}
